﻿    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.IO;
    using System.Web.SessionState;

    namespace DemoSwfUpload
    {
        /// <summary>
        /// $codebehindclassname$ 的摘要说明
        /// </summary>
        public class upload : IHttpHandler, IRequiresSessionState
        {

            public void ProcessRequest(HttpContext context)
            {
                try
                {
                    HttpPostedFile file;
                    for (int i = 0; i < context.Request.Files.Count; ++i)
                    {
                        file = context.Request.Files[i];
                        if (file == null || file.ContentLength == 0 || string.IsNullOrEmpty(file.FileName))
                            continue;
                        else
                        {
                            file.SaveAs(HttpContext.Current.Server.MapPath("file/" + Path.GetFileName(file.FileName)));
                            context.Session["upname"] =file.FileName;
                        }
                    }
                }
                catch (Exception ex)
                {
                    context.Response.StatusCode = 500;
                    context.Response.Write(ex.Message+ex.StackTrace);
                    context.Response.End();
                }
                finally
                {
                    context.Response.End();
                }
            }

            public bool IsReusable
            {
                get
                {
                    return true;
                }
            }
        }
    }
